package com.sims.base;

import java.io.Serializable;

public class BaseResponse<T> implements Serializable {

    public static final String SUCESS_CODE = "200";

    public static final String SUCESS_MESSAGE = "success";

    public static final String ERROR_CODE = "0";

    public static final String ERROR_MESSAGE = "error";

    private static final long serialVersionUID = 1L;

    

	private String code = SUCESS_CODE;
    private String message = SUCESS_MESSAGE;

    private T data;
    
    public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

    public boolean isSuccess() {
        return SUCESS_CODE.equals(code);
    }

    public BaseResponse(){
    }
    
    public BaseResponse(String message) {
        super();
        this.message = message;
    }

    public BaseResponse(String code, String message) {
        super();
        this.code = code;
        this.message = message;
    }
    public BaseResponse(String code, String message,T data) {
        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 返回成功消息
     *
     * @return 成功消息
     */
    public static <T> BaseResponse<T> success() {
        return new BaseResponse<T>();
    }

    /**
     * 返回成功数据
     *
     * @return 成功消息
     */
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<T>(BaseResponse.SUCESS_CODE, SUCESS_MESSAGE, data);
    }

    /**
     * 返回成功消息
     *
     * @param message 返回内容
     * @param data    数据对象
     * @return 成功消息
     */
    public static <T> BaseResponse<T> success(String message, T data) {
        return new BaseResponse<T>(BaseResponse.SUCESS_CODE, message, data);
    }

    /**
     * 返回错误消息
     */
    public static <T> BaseResponse<T> error() {
        return new BaseResponse<T>(BaseResponse.ERROR_CODE, BaseResponse.ERROR_MESSAGE);
    }

    /**
     * 返回错误消息
     *
     * @param message 返回内容
     * @return 警告消息
     */
    public static <T> BaseResponse<T> error(String message) {
        return new BaseResponse<T>(BaseResponse.ERROR_CODE, message);
    }

    /**
     * 返回错误消息
     *
     * @param message 返回内容
     * @param data    数据对象
     * @return 警告消息
     */
    public static <T> BaseResponse<T> error(String message, T data) {
        return new BaseResponse<T>(BaseResponse.ERROR_CODE, BaseResponse.ERROR_MESSAGE, data);
    }

    /**
     * 返回错误消息
     *
     * @param code    返回代码
     * @param message 返回内容
     * @param data    数据对象
     * @return 警告消息
     */
    public static <T> BaseResponse<T> error(String code, String message, T data) {
        return new BaseResponse<T>(code, BaseResponse.ERROR_MESSAGE, data);
    }

}
